package com.kfh.ybracelet.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.joooonho.SelectableRoundedImageView;
import com.kfh.ybracelet.R;
import com.kfh.ybracelet.bean.GroupSettingBean;

import java.util.ArrayList;

/**
 * 移交群主的adapter
 * Created by Aaron on 16/4/19.
 */
public class ChangeMasterAdapter extends BaseAdapter {

    private Context ctx;
    private ArrayList<GroupSettingBean.TopicEntity.UserListEntity> userList;

    public ChangeMasterAdapter(Context ctx, ArrayList<GroupSettingBean.TopicEntity.UserListEntity> userList) {
        this.ctx = ctx;
        this.userList = userList;
    }

    @Override
    public int getCount() {
        return userList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;

        if (convertView == null) {

            convertView = View.inflate(ctx, R.layout.item_address_book, null);
            viewHolder = new ViewHolder();
            viewHolder.iv_pic = (SelectableRoundedImageView) convertView.findViewById(R.id.iv_pic);
            viewHolder.tv_nickname = (TextView) convertView.findViewById(R.id.tv_nickname);
            convertView.setTag(viewHolder);

        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        if (userList.get(position).user == null)
            return convertView;

        Glide.with(ctx)
                .load(userList.get(position).user.imgUrl)
                .dontAnimate().diskCacheStrategy(DiskCacheStrategy.SOURCE).fitCenter()
                .placeholder(R.mipmap.temp_pic).into(viewHolder.iv_pic);

        viewHolder.tv_nickname.setText(userList.get(position).user.nickName);

        return convertView;
    }

    private class ViewHolder {
        private SelectableRoundedImageView iv_pic;
        private TextView tv_nickname;

    }
}
